package com.kfm.pm.pro;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

public class PropertiesTest {

    public static void main(String[] args) throws IOException {
        // Hashtable子类 键值都是String类型，
        Properties properties = new Properties(); // 构建空的Properties对象
        properties.put("username", "kfm");
        properties.put("password", "123456");
        System.out.println(properties.get("username"));
        System.out.println(properties.getProperty("username")); // get()
        System.out.println(properties.getProperty("username1", "kaifamiao")); // key有映射 返回映射的值 没有映射就返回第二个参数
        properties.store(new FileOutputStream("E:\\KFM\\kfm7\\day0911\\src\\com\\kfm\\pm\\pro\\test.txt"), "备注");
        properties.load(new FileInputStream("E:\\KFM\\kfm7\\day0911\\src\\com\\kfm\\pm\\test.txt"));
        System.out.println(properties);
        System.out.println(properties.getProperty("username"));
        System.out.println(properties.getProperty("password"));
    }
}
